﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using WxStockWinSvc.BIZs;
using DX.CRC.Log;
using WxStockWinSvc.Commons;

namespace WxStockWinSvc
{
    public partial class MainService : ServiceBase
    {
        Timer _timer;
        public MainService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            CrcLog.Log4Debug("服务准备启动");
            _timer = new Timer(1000 * 60);
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
            _timer.Start();
            CrcLog.Log4Debug("服务启动成功");
        }

        void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            DateTime dtNow = DateTime.Now;

            //if (dtNow.Hour == 0 && dtNow.Minute == 8)
            //    BizLoadStock163.LoadStocksFrom163();

            if (dtNow.ToString("HH:mm") == CommonUtil.RunTime)
                BizLoadStock163.LoadStocksFrom163();
        }

        protected override void OnStop()
        {
            CrcLog.Log4Debug("服务停止");
        }
    }
}
